﻿// 2-2 前t个组合结果 (20分).cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
#include <iostream>
#include <algorithm>
#include <string>

#include<set>
#include<math.h>
using namespace std;
bool cmp(char a, char b)
{
	return a > b;
}
int jiecheng(int input)
{
	int re = 1;
	for (; input > 0; input--)
	{
		
		re= input * re;
	}
	return re;
}
int main()
{
	string str;

	set<string> s2;
	int n,r,i,t;
	cin >> n>>r>>t;
	int j = n;
	


	int nu = 1;
	for (; j > 0; j--)
	{
		str.insert(0, to_string(j));
		
	}


	//cin >> str;

	sort(str.begin(), str.end(), cmp);

	nu = jiecheng(n - r) ;
	//cout << "nu" << nu << endl;
	int nu1=nu-1;
	//s1.push(atoi(str.c_str()) / pow(10, n - r));
	

	int k;
	int kk;
	int flag =1;
	string zx=str;
	string zx1=zx;
	//for (int jj = 0; jj < n-r; jj++)
	{

		zx.erase(zx.end()-n+r,zx.end());
	}
	for ( kk = 0; kk < zx.size(); kk++)
	{
	
		cout << " " << zx[kk];
	}
	if (n > r) {
		cout << "\n";
	}
	s2.insert(zx);
	while (next_permutation(zx.begin(), zx.end(),cmp ))
	{
		
		//cout << "next_permutation(zx.begin(), zx.end())==1" << endl;
		s2.insert(zx);
	}

	//cout << "nu:"<< nu;
	if (n > r&&t>1) {

		for (j = 0; j < t - 1; j++)
		{
			next_permutation(str.begin(), str.end(), cmp);
			{
				//cout << str << endl;
				if (nu1 % nu == 0)
				{
					zx = str;
					zx.erase(zx.end() - n + r, zx.end());
					zx1 = zx;

					if (s2.count(zx) == 0) //zx不在集合中，则将其全排列放入集合并输出
					{
						//逐个输出zx的字符
						for (int kk = 0; kk < zx1.size(); kk++)
						{
							//if (j == t - 1 && kk == zx1.size() - 1) {}
							//else {
							cout << " " << zx1[kk];
							//}
						}
						if (j != t - 2) {
							cout << "\n";
						}
						//cout << next_permutation(zx.begin(), zx.end()) << endl;
						s2.insert(zx);//这里的插入超关键，因为下一个while里的直接开始排列，最后集合里不包括这个初始的zx了
						while (next_permutation(zx.begin(), zx.end(), cmp))
						{
							//cout << zx;
							//cout << "next_permutation(zx.begin(), zx.end())==1" << endl;
							s2.insert(zx);
						}
						//s1.pop();
					}
					else
					{
						//s1.pop();
						j--;
					}
					//cout << s1.top() << endl;
					//s1.push(atoi(str.c_str()) / pow(10, n - r));
				}
				else
				{
					//s1.pop();
					j--;
				}
				//cout << str << endl;
				nu1++;
			}
			//sort(zx.begin(), zx.end());//zx不排序就不能全排列 字符串也可以快排解决



		}
	}
	return 0;
}